<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Title</title>
</head>
<body>
<script>
    new Promise((resolve,reject)=>{
        setTimeout(()=>{
            // resolve('成功的数据')
            reject('失败的数据')
        },1000)
    }).then(
        value => {
            console.log('onResolved1',value)
        }
    ).catch(
        reason=>{
            console.log('onrejected1',reason)
        }
    )

    // 产生一个成功值为1的promise
    const p1 = new Promise((resolve,reject)=>{
        setTimeout(()=>{
            resolve(1)
        },100)
    })
    console.log(p1)
    const p2 = Promise.resolve(2)
    const p3 = Promise.reject(3)

    p1.then(value => {console.log(value)})
    p2.then(value => {console.log(value)})
    p3.then(null,reason => {console.log(reason)})
    p3.catch(reason=>{console.log(reason)})

    // const pAll = Promise.all([p1,p2,p3])
    const pAll = Promise.all([p1,p2])
    pAll.then(
        values => {
            console.log('all onResolved',values)
        },
        reason => {
            console.log('all onRejected',reason)
        }
    )

    const pRace = Promise.race([p1,p2,p3])
    pRace.then(
        value => {
            console.log('all onResolved',value)
        },
        reason => {
            console.log('all onRejected',reason)
        }
    )

</script>
</body>
</html>
